import $axios from './axios.js';
// 登录
export const login = param => {
  return new Promise((resolve) => {
    $axios.post(`/base-server/checkUser`,param).then((response) => {
      const data = response.data;
      if(data.success) {
        resolve(data)
      }else {
        $Message.error('请求错误')
      }
    }).catch( error => {
      console.log(error);
      $Message.error('请求错误')
    });
  });
};


export const getBlog = (param) => {
  return new Promise((resolve) => {
    $axios.post(`/base-server/articles`,param).then((response) => {
      const data = response.data;
      if(data.success) {
        resolve(data)
      }else {
        $Message.error('请求错误')
      }
    }).catch( error => {
      console.log(error);
      $Message.error('请求错误')
    });
  });
};
export const getBlogById = (param) => {
  return new Promise((resolve) => {
    $axios.post(`/base-server/queryArticleById`,param).then((response) => {
      const data = response.data;
      if(data.success) {
        resolve(data)
      }else {
        $Message.error('请求错误')
      }
    }).catch( error => {
      console.log(error);
      $Message.error('请求错误')
    });
  });
};
export const addBlog = (param) => {
  return new Promise((resolve) => {
    $axios.post(`/base-server/addArticles`,param).then((response) => {
      const data = response.data;
      if(data.success) {
        resolve(data)
      }else {
        $Message.error('请求错误')
      }
    }).catch( error => {
      console.log(error);
      $Message.error('请求错误')
    });
  });
};
export const updateBlog = (param) => {
  return new Promise((resolve) => {
    $axios.post(`/base-server/updateArticles`,param).then((response) => {
      const data = response.data;
      if(data.success) {
        resolve(data)
      }else {
        $Message.error('请求错误')
      }
    }).catch( error => {
      console.log(error);
      $Message.error('请求错误')
    });
  });
};
export const deleteBlog = (param) => {
  return new Promise((resolve) => {
    $axios.post(`/base-server/deleteArticles`,param).then((response) => {
      const data = response.data;
      if(data.success) {
        resolve(data)
      }else {
        $Message.error('请求错误')
      }
    }).catch( error => {
      console.log(error);
      $Message.error('请求错误')
    });
  });
};


export const getTags = (param) => {
  return new Promise((resolve) => {
    $axios.post(`/base-server/tags`,param).then((response) => {
      const data = response.data;
      if(data.success) {
        resolve(data)
      }else {
        $Message.error('请求错误')
      }
    }).catch( error => {
      console.log(error);
      $Message.error('请求错误')
    });
  });
};

export const getProject = (param) => {
  return new Promise((resolve) => {
    $axios.post(`/base-server/projects`,param).then((response) => {
      const data = response.data;
      if(data.success) {
        resolve(data)
      }else {
        $Message.error('请求错误')
      }
    }).catch( error => {
      console.log(error);
      $Message.error('请求错误')
    });
  });
};

export const getProjectById = (param) => {
  return new Promise((resolve) => {
    $axios.post(`/base-server/queryProjectsById`,param).then((response) => {
      const data = response.data;
      if(data.success) {
        resolve(data)
      }else {
        $Message.error('请求错误')
      }
    }).catch( error => {
      console.log(error);
      $Message.error('请求错误')
    });
  });
};
export const addProject = (param) => {
  return new Promise((resolve) => {
    $axios.post(`/base-server/addProject`,param).then((response) => {
      const data = response.data;
      if(data.success) {
        resolve(data)
      }else {
        $Message.error('请求错误')
      }
    }).catch( error => {
      console.log(error);
      $Message.error('请求错误')
    });
  });
};
export const updateProject = (param) => {
  return new Promise((resolve) => {
    $axios.post(`/base-server/updateProject`,param).then((response) => {
      const data = response.data;
      if(data.success) {
        resolve(data)
      }else {
        $Message.error('请求错误')
      }
    }).catch( error => {
      console.log(error);
      $Message.error('请求错误')
    });
  });
};
export const deleteProject = (param) => {
  return new Promise((resolve) => {
    $axios.post(`/base-server/deleteProject`,param).then((response) => {
      const data = response.data;
      if(data.success) {
        resolve(data)
      }else {
        $Message.error('请求错误')
      }
    }).catch( error => {
      console.log(error);
      $Message.error('请求错误')
    });
  });
};

export const getUserList = (param) => {
  return new Promise((resolve) => {
    $axios.post(`/base-server/userList`,param).then((response) => {
      const data = response.data;
      if(data.success) {
        resolve(data)
      }else {
        $Message.error('请求错误')
      }
    }).catch( error => {
      console.log(error);
      $Message.error('请求错误')
    });
  });
};
export const addOrEditUser = (param) => {
  return new Promise((resolve) => {
    $axios.post(`/base-server/addOrEditUser`,param).then((response) => {
      const data = response.data;
      if(data.success) {
        resolve(data)
      }else {
        $Message.error('请求错误')
      }
    }).catch( error => {
      console.log(error);
      $Message.error('请求错误')
    });
  });
};
export const deleteUser = (param) => {
  return new Promise((resolve) => {
    $axios.post(`/base-server/deleteUser`,param).then((response) => {
      const data = response.data;
      if(data.success) {
        resolve(data)
      }else {
        $Message.error('请求错误')
      }
    }).catch( error => {
      console.log(error);
      $Message.error('请求错误')
    });
  });
};
export const enableOrDisableUser = (param) => {
  return new Promise((resolve) => {
    $axios.post(`/base-server/enableOrDisableUser`,param).then((response) => {
      const data = response.data;
      if(data.success) {
        resolve(data)
      }else {
        $Message.error('请求错误')
      }
    }).catch( error => {
      console.log(error);
      $Message.error('请求错误')
    });
  });
};

export const getLinkList = (param) => {
  return new Promise((resolve) => {
    $axios.post(`/base-server/links`,param).then((response) => {
      const data = response.data;
      if(data.success) {
        resolve(data)
      }else {
        $Message.error('请求错误')
      }
    }).catch( error => {
      console.log(error);
      $Message.error('请求错误')
    });
  });
};

export const addOrEditLink = (param) => {
  return new Promise((resolve) => {
    $axios.post(`/base-server/addOrEditLink`,param).then((response) => {
      const data = response.data;
      if(data.success) {
        resolve(data)
      }else {
        $Message.error('请求错误')
      }
    }).catch( error => {
      console.log(error);
      $Message.error('请求错误')
    });
  });
};

export const deleteLink = (param) => {
  return new Promise((resolve) => {
    $axios.post(`/base-server/deleteLink`,param).then((response) => {
      const data = response.data;
      if(data.success) {
        resolve(data)
      }else {
        $Message.error('请求错误')
      }
    }).catch( error => {
      console.log(error);
      $Message.error('请求错误')
    });
  });
};

export const getDiscussList = (param) => {
  return new Promise((resolve) => {
    $axios.post(`/base-server/discussList`,param).then((response) => {
      const data = response.data;
      if(data.success) {
        resolve(data)
      }else {
        $Message.error('请求错误')
      }
    }).catch( error => {
      console.log(error);
      $Message.error('请求错误')
    });
  });
};

export const enableOrDisableDiscuss = (param) => {
  return new Promise((resolve) => {
    $axios.post(`/base-server/enableOrDisableDiscuss`,param).then((response) => {
      const data = response.data;
      if(data.success) {
        resolve(data)
      }else {
        $Message.error('请求错误')
      }
    }).catch( error => {
      console.log(error);
      $Message.error('请求错误')
    });
  });
};

export const deleteDiscuss = (param) => {
  return new Promise((resolve) => {
    $axios.post(`/base-server/deleteDiscuss`,param).then((response) => {
      const data = response.data;
      if(data.success) {
        resolve(data)
      }else {
        $Message.error('请求错误')
      }
    }).catch( error => {
      console.log(error);
      $Message.error('请求错误')
    });
  });
};